package com.xinjie.www.service.manager;

import com.xinjie.www.dao.BaseDao;
import com.xinjie.www.dao.manager.ManagerDao;
import com.xinjie.www.dao.manager.MangerDaoImpl;
import com.xinjie.www.po.Manager;

import java.sql.Connection;
import java.sql.SQLException;

public class ManagerServiceImpl implements ManagerService{
    private final ManagerDao managerDao;

    public ManagerServiceImpl(){
        managerDao = new MangerDaoImpl();
    }
    @Override
    public Manager login(String name, String password) {
        Connection conn = null;
        Manager manager =null;

        try {
            conn= BaseDao.getConnection();
            manager= managerDao.getLoginManger(conn,name);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            boolean b =BaseDao.closeResource(conn,null,null);
            if (b){
                System.out.println("关闭成功");
            }
        }
        return manager;
    }

    @Override
    public boolean doBan(int userId, int tiebaId)  {
        Connection conn = null;
        boolean flag = false;
        try {
            conn= BaseDao.getConnection();
            int i = managerDao.doBan(conn, userId, tiebaId);
            if (i>0){
                flag=true;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            BaseDao.closeResource(conn,null,null);
        }
        return flag;
    }
}
